package org.hxyjs.service.impl;


import org.hxyjs.dao.OrderdetailsDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Orderdetails;
import org.hxyjs.entity.Orderdetails;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.OrderdetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("OrderdetailsService")
public class OrderdetailsServiceImpl implements OrderdetailsService {
    @Resource
    OrderdetailsDao orderdetailsDao;
    @Override
    public DTO<Orderdetails> getAllOrderdetailss()  throws Exception{
        List<Orderdetails> orderdetailss = orderdetailsDao.getAllOrderdetailss();
        MessageEnum messageEnum  = Optional.ofNullable(orderdetailss).isPresent()?MessageEnum.GETORDERDETAILSSUCCESS: MessageEnum.GETORDERDETAILSFAIL;
        return new DTO<Orderdetails>(messageEnum.getCode(),messageEnum.getMessage(),orderdetailss);
    }

    @Override
    public DTO<Orderdetails> deleteOrderdetailsByOdno(String odno)  throws Exception{
        Integer result = orderdetailsDao.deleteOrderdetailsByOdno(odno);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEORDERDETAILSSUCCESS:MessageEnum.DELETEORDERDETAILSFAIL;
        return new DTO<Orderdetails>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Orderdetails> updateOrderdetailsByOdno(Orderdetails orderdetails)  throws Exception{
        Integer result = orderdetailsDao.updateOrderdetailsByOdno(orderdetails);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEORDERDETAILSSUCCESS:MessageEnum.UPDATEORDERDETAILSFAIL;
        return new DTO<Orderdetails>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Orderdetails> addOrderdetails(Orderdetails orderdetails) throws Exception {
        Integer result = orderdetailsDao.addOrderdetails(orderdetails);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDORDERDETAILSSUCCESS:MessageEnum.ADDORDERDETAILSFAIL;
        return new DTO<Orderdetails>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Orderdetails> getOrderdetailsByPage(PageInfo pageInfo ) throws Exception {
        List<Orderdetails> orderdetailss = orderdetailsDao.getOrderdetailsByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(orderdetailss).isPresent()?MessageEnum.GETORDERDETAILSSUCCESS: MessageEnum.GETORDERDETAILSFAIL;
        return new DTO<Orderdetails>(messageEnum.getCode(),messageEnum.getMessage(),orderdetailss,pageInfo);
    }
}
